const { contextBridge, ipcRenderer, BrowserWindow } = require('electron');
//path = require('path');
const Baidu = require("./baidu");
let baidu = new Baidu();

//const pdfmerger = require("./pdfMerger.mjs");
let pdf = null;
(async () => {
	const { pdfmerger } = await import('./pdfMerger.mjs');
	pdf = pdfmerger;
})();
//添加重新加载函数
baidu.cb_reload = ()=>{
	ipcRenderer.send("reload");
}

contextBridge.exposeInMainWorld("BaiduPan", async (fun, ...args)=>{
	if(baidu[fun]){
		return await baidu[fun](...args);
	}else{
		console.log("not find function", fun)
	}
});

contextBridge.exposeInMainWorld("openPlayer", (url)=>{
	ipcRenderer.send("openPlayer", url);
});

contextBridge.exposeInMainWorld("pdfMerger", (dir)=>{
	pdf && pdf(dir);
});
